﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BricksProblemSolver
{
    public class BrickWall<T> : ICloneable
        where T : IBrickRow
    {
        private T[] _rows;

        public BrickWall(int height)
        {
            _rows = new T[height];
        }

        public int Height
        {
            get { return _rows.Length; }
        }

        public T this[int index]
        {
            get
            {
                return _rows[index];
            }
            set
            {
                _rows[index] = value;
            }
        }

        public object Clone()
        {
            var wall = new BrickWall<T>(Height);
            Array.Copy(_rows, wall._rows, Height);
            return wall;
        }

        public override string ToString()
        {
            return string.Join("\n", _rows.Select(x => x == null ? "" : x.ToString()));
        }
    }
}
